#include "vertex.h"
#include "edge.h"
#include "dijkstra.h"

Vertex::Vertex(int id, Vertex* next, int position,double lat,double lon)
{
    this->id_ = id;
    this->next_ = next;
    this->position = position;
    this->lat=lat;
    this->lon=lon;
}

Vertex::~Vertex()
{
    if (this->next_)
        delete this->next_;
    this->next_ = 0;
    if (this->edges_)
        delete this->edges_;
    this->edges_ = 0;
}

int Vertex::getId()
{
    return this->id_;
}

void Vertex::connectTo(Vertex* toVertex, int weight)
{
    if (!this->edges_)
        this->edges_ = new Edge(toVertex, 0, weight);
    else
        this->edges_->insertNext(weight, toVertex, 0);
    this->nodes_.push_back(GNode(toVertex->position, weight));
}

void Vertex::connectVertex(Edge* edge, Vertex* toVertex, int weight)
{
    if (!edge)
        edge = new Edge(toVertex, 0, weight);
    else
        connectVertex(edge, toVertex, weight);
}

Vertex* Vertex::getNext()
{
    return this->next_;
}

Edge* Vertex::getFirstEdge()
{
    return this->edges_;
}

void Vertex::insertNext(int id,double lat,double lon)
{
    if (!this->next_)
        this->next_ = new Vertex(id, 0, position + 1,lat,lon);
    else
        this->next_->insertNext(id,lat,lon);
}

void Vertex::printGraph()
{
    printf("%d \n", this->id_);
    this->printEdges();
    if (this->next_)
        this->next_->printGraph();
}

void Vertex::printEdges()
{
    if (this->edges_)
        this->edges_->print();
}

int Vertex::getSize() const
{
    if (this->next_)
        return 1 + next_->getSize();
    return 1;
}

std::vector<std::pair<int, int> > Vertex::getListOfEdges()
{
    return this->nodes_;
}
